
module.exports = function ($scope, $resource, $modal, toaster, $state, date2str){

    $scope.searchform = {};
    $scope.date = {
		'opened': false,
		'opened1': false
	}

    /* 分页
       * ========================================= */
    $scope.maxSize = 5;            //最多显示多少个按钮
    $scope.bigCurrentPage = 1;      //当前页码
    $scope.itemsPerPage = 10;         //每页显示几条

    $scope.load = function () {
        var para = {
            pageNo: $scope.bigCurrentPage,
            pageSize: $scope.itemsPerPage,
            start_time : date2str($scope.date.lable),
            end_time : date2str($scope.date.lable1)
        };

        angular.extend(para, $scope.searchform);

        $resource('/api/as/goc/enterpriserecord/companyrecordlist', {}, {}).save(para, function (res) {
            console.log(res);

            if (res.errcode !== 0) {
                toaster.error({title: '', body: res.errmsg});
                return;
            }

            $scope.objs = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;

        });
    };
    $scope.load();

    //企业详情
    $scope.info = function(obj){
     
        var para = $state.get('app.enterpriseapplyinfo');
        var resolve = {
            obj : function(){
                return obj;
            },
            title : function(){
                return '企业备案信息';
            },
        };
        angular.extend(para.resolve, resolve);

        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  

        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
    }
    
    //设置
    $scope.setup = function(obj){
     
        var para = $state.get('app.adoptsetupinfo');
        var resolve = {
            obj : function(){
                return obj;
            },
        };
        angular.extend(para.resolve, resolve);

        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  
            $scope.load();
        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
    }

    //撤销（已过期）
	$scope.applyupdate = function(id) {
        if(confirm("撤销后备案状态变更为已过期，是否要撤销？")) {
            $resource('/api/ac/goc/enterpriseRecordService/updateRecordState', {}, {}).save({'id' : id, 'record_type' : '2'}, function(res){
                if (res.errcode === 0) {
                    toaster.success({title: '', body: '撤销成功'});
                    $scope.load();
                } else {
                    toaster.error({title: '', body: res.errmsg});
                }
            });
	    }
    }

    $scope.dateOpen = function ($event, item) {
		console.log('open');
		$event.preventDefault();
		$event.stopPropagation();
		item.opened = true;
	};

	$scope.dateOpen1 = function ($event, item) {
		console.log('open');
		$event.preventDefault();
		$event.stopPropagation();
		item.opened1 = true;
	};



};